package srx.open.com.widgets;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import srx.open.com.R;
import srx.open.com.activity.ExtendBaseActivity;

/**
 * APP更新界面.
 */
public class AppUpdateDialogWindow {

    private Context mContext;
    private AlertDialog alertDialog;
    private int layoutID = -1;

    private Button selectBtn;
    private Button okBtn;
    private TextView titleTv;
    private ImageView imageView;
    private ProgressBar pb;

    private ProgressBar npb;
    private TextView updateiv;

    public AppUpdateDialogWindow(ExtendBaseActivity t, final DialogCallBack cb) {
        alertDialog = new AlertDialog.Builder(t).create();
        layoutID = R.layout.pup_app_update_dialog;
        alertDialog.show();
        Window window = alertDialog.getWindow();
        window.setContentView(layoutID);
        titleTv = (TextView) window.findViewById(R.id.title_tv); // 标题栏.
        updateiv = (TextView) window.findViewById(R.id.update_iv); // 更新内容.
        okBtn = (Button) window.findViewById(R.id.down_btn); // 点击下载
        npb = (ProgressBar) window.findViewById(R.id.loading_npb); // 下载进度
        /* 回调 */
        if (cb != null) {
            okBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    cb.onOkBtnClick(npb);
                }
            });
        }
    }

    public void updateAppShow(final String title, final String content) {
        alertDialog.show();
        /* 设置标题栏代码 */
        if (title != null) {
            titleTv.setText(title);
        }
        /* 更新APP的内容 */
        if (!TextUtils.isEmpty(content)) {
            updateiv.setText(content);
        }
    }

    public void setProgressBar(int num) {
        npb.setVisibility(View.VISIBLE);
        npb.setProgress(num);
        updateiv.setVisibility(View.GONE);
    }

    public void hideProgressbar() {
        try {
            pb.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void dismiss() {
        alertDialog.dismiss();
    }

    /**
     * 设置标题.
     *
     * @param id
     */
    public void setTitle(int id) {
        titleTv.setText(id);
    }

    public void setTitle(String str) {
        titleTv.setText(str);
    }

    /**
     * 设置内容.
     *
     * @param id
     */
    public void setMessage(int id) {
		/* 暂时不定义 */
    }

    public static class DialogCallBack {
        public void onOkBtnClick(View v) {
        }

    }
}
